package com.somnus.androidkotlindemo.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import com.chad.library.adapter.base.entity.MultiItemEntity
import com.somnus.androidkotlindemo.R
import com.somnus.androidkotlindemo.adapter.ExpandableListAdapter
import com.somnus.androidkotlindemo.bean.Level0Item
import com.somnus.androidkotlindemo.bean.Level1Item
import kotlinx.android.synthetic.main.activity_base_recycler_adapter.*

class ExpandableListActivity : AppCompatActivity() {


    var mList: ArrayList<MultiItemEntity> = ArrayList<MultiItemEntity>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_recycler_view)

        mList = getData()
        val adapter = ExpandableListAdapter(mList)
        recycler.layoutManager = LinearLayoutManager(this)
        recycler.adapter = adapter

    }

    fun getData(): ArrayList<MultiItemEntity> {
        val lv0 = 5
        val lv1 = 3
        var res = ArrayList<MultiItemEntity>()
        for (index in 0..lv0) {
            val level0Item = Level0Item("This is " + index + "th item in Level 0", "subtitle of " + index)
            for (index2 in 0..lv1) {
                val Level1Item = Level1Item("this is child title $index2", "child subtitle $index2")
                level0Item.addSubItem(Level1Item)
            }
            res.add(level0Item)
        }
        return res
    }

    //创建一个 伴生对象
    companion object {
        fun startExpandablListActivity(context: Context) {

            val mIntent = Intent()
            mIntent.setClass(context, ExpandableListActivity::class.java)
            context.startActivity(mIntent)
        }
    }
}
